----------------------------------Spell Variables--------------------------------------
SPELL.m_iSpellID = 101010 -- Whatever value you want as long as it doesn't override any other spells' IDs.
SPELL.m_iRange = 480
SPELL.m_sName = "MAA Auto Attack"
SPELL.m_sToolTip =	[[Blast the target with
					  fire damage.]]
SPELL.m_sIcon = "devin/blackbetty/spells/mage/fireblast.png"
SPELL.m_iCoolDown = 4
SPELL.m_iManaCost = 50
SPELL.m_bRequiresTarget = true
SPELL.m_iSpellType = SPELLTYPE_MAGICDAMAGE

---------------------------------------------------------------------------------------

function SPELL:Cast( pl, target )
	timer.Simple(0.1, function()
		pl:SetNWBool("Casting", false) 
		pl:SetNWBool("Casted", false)
	end)

	local range = self.m_iRange
	
	print("Casted "..self.m_sName.."!")
		
	if(target && target:IsValid() && target != pl && target:Alive()) then
		pl:EmitSound("devin/blackbetty/weapons/castsounds/FireCast.wav", 100, 100+math.random(-10,10))
		ParticleEffectAttach( "fire_hands_instacast", PATTACH_POINT_FOLLOW, pl, pl:LookupAttachment("anim_attachment_RH"))
		if(pl:IsPlayer())then
			pl:DoAnimationEvent(ACT_HL2MP_GESTURE_RANGE_ATTACK_SLAM)
		else
			pl:RestartGesture(ACT_HL2MP_GESTURE_RANGE_ATTACK_SLAM)
		end
		timer.Simple(0.05, function()
			if(pl:GetPos():Distance(target:GetPos()) < range)then
				pl:EmitSound("devin/blackbetty/weapons/hit/Fire"..math.random(1,3)..".wav", 100, 100+math.random(-10,10))
				ParticleEffect( "impact_firebig", target:GetPos() + Vector(0, 0, 32), Angle(0,0,0), pl )
				if(SERVER)then
					local dmginfo_fbst = DamageInfo()
						dmginfo_fbst:SetDamage( 5 ) 
						dmginfo_fbst:SetDamageType( DMG_GENERIC )
						dmginfo_fbst:SetAttacker( pl ) 
						dmginfo_fbst:SetDamageForce( Vector( 0, 0, 1000 ) ) 
					target:TakeDamageInfo( dmginfo_fbst )
					if(timer.Exists("immolate_on_"..target:EntIndex()..""))then
						timer.Destroy("immolate_on_"..target:EntIndex().."")
					end
					timer.Create("immolate_on_"..target:EntIndex().."", 1, 10, function() 
						if(target:Health() <= 0) then 
							timer.Destroy("immolate_on_"..target:EntIndex().."")  
							target:SetColor(Color(255, 255, 255, 255))
						else
							local dmginfo_im = DamageInfo()
								dmginfo_im:SetDamage( 2 ) 
								dmginfo_im:SetDamageType( DMG_GENERIC )
								dmginfo_im:SetAttacker( pl ) 
								dmginfo_im:SetDamageForce( Vector( 0, 0, 1000 ) ) 
							target:TakeDamageInfo( dmginfo_im )
							
							ParticleEffect( "impact_firesmall", target:GetPos() + Vector(0, 0, 32), Angle(0,0,0), pl )
							target:EmitSound("devin/blackbetty/weapons/hit/Immolate.wav", 35, 100+math.random(10,30))
						end
					end)
				end
			end
		end)
	end
end




